package com.nuoniu.sibanyun.controller.crm;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.crm.CrmActivity;
import com.nuoniu.sibanyun.entity.dto.CrmActivityDto;
import com.nuoniu.sibanyun.entity.dto.CrmActivitySearchDto;
import com.nuoniu.sibanyun.entity.vo.CrmActivityVo;
import com.nuoniu.sibanyun.entity.vo.SelectVo;
import com.nuoniu.sibanyun.service.crm.ICrmActivityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  市场活动
 * </p>
 *
 * @author baiqiang
 * @since 2020-08-15
 */
@RestController
@RequestMapping("/crm/activity")
@Api(value="市场活动 ",tags={"市场活动"})
public class CrmActivityController extends BaseController {

    @Autowired
    private ICrmActivityService crmActivityService;

    /**
     * 获取市场活动列表
     */
    @GetMapping("page")
    @ApiOperation(value = "分页",tags = "APP_市场活动")
    public HttpResult<Page<CrmActivity>> pageBusiness(Page page, CrmActivitySearchDto crmActivitySearchDto) {
        return HttpResult.ok(crmActivityService.pageCrmActivity(page, crmActivitySearchDto));
    }

    @PostMapping("save")
    @ApiOperation(value = "保存",tags = "APP_市场活动")
    public HttpResult save(@RequestBody CrmActivityDto crmActivityDto){
        crmActivityService.saveActivity(crmActivityDto);
        return HttpResult.ok();
    }

    /**
     * 获取市场活动详情
     */
    @GetMapping("detail")
    @ApiOperation(value = "详情",tags = "APP_市场活动")
    public HttpResult<CrmActivityVo> detail(Integer id) {
        return HttpResult.ok(crmActivityService.detail(id));
    }

    /**
     * 批量删除
     */
    @PostMapping("batchDelete")
    @ApiOperation(value = "批量删除",tags = "APP_市场活动")
    public HttpResult batchDelete(@RequestBody List<Integer> ids) {
        crmActivityService.batchDelete(ids);
        return HttpResult.ok();
    }

    /**
     * 检查（租户的）市场活动名称 是否存在
     * @param activityTitle
     * @return
     */
    @GetMapping("checkActivityTitle")
    @ApiOperation(value = "检查（租户的）市场活动名称 是否存在",tags = "APP_市场活动")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value="当前编辑的市场活动ID,新增就不传",required=true,paramType="query"),
            @ApiImplicitParam(name="activityTitle",value="市场活动名称",required=true,paramType="query"),
    })
    public HttpResult checkActivityTitle(Integer id,String activityTitle) {
        return HttpResult.ok(crmActivityService.checkActivityTitle(id,activityTitle));
    }

    /**
     * 获取 公司市场活动下拉数据
     * @return
     */
    @GetMapping("listCompanyActivities")
    @ApiOperation(value = "获取 公司市场活动下拉数据",tags = "APP_市场活动")
    public HttpResult<List<SelectVo>> listCompanyActivities() {
        return HttpResult.ok(crmActivityService.listCompanyActivities());
    }


}
